package com.boboPlanet.user.service.impl;

import cn.xuyanwu.spring.file.storage.FileInfo;
import cn.xuyanwu.spring.file.storage.FileStorageService;
import cn.xuyanwu.spring.file.storage.recorder.FileRecorder;
import com.boboPlanet.comm.context.LoginUserContext;
import com.boboPlanet.comm.entity.po.LoginDetailInfoPO;
import com.boboPlanet.comm.entity.po.LoginUserInfoPO;
import com.boboPlanet.comm.exception.BusinessException;
import com.boboPlanet.comm.result.ResponseResult;
import com.boboPlanet.user.enums.FileTypeEnum;
import com.boboPlanet.user.mapper.UserResumeMapper;
import com.boboPlanet.user.service.UserResumeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2023/3/13
 **/
@Service
@Slf4j
public class UserResumeServiceImpl implements UserResumeService {

    @Resource
    private FileUploadServiceFactory fileUploadServiceFactory;

    @Resource
    private UserResumeMapper userResumeMapper;

    @Override
    public String uploadResumeAvatar(MultipartFile file) {

        List<String> mediaTypes = Arrays.asList(FileTypeEnum.JPG.getType(),FileTypeEnum.PNG.getType(),FileTypeEnum.WEBP.getType(),FileTypeEnum.JPEG.getType());
        if (!mediaTypes.contains(file.getContentType())){
            throw BusinessException.build("文件类型不符合规范,请重新上传(只支持jpg/png/webp格式)...");
        }

        return fileUploadServiceFactory.uploadResumeAvatar(file);
    }

    @Override
    public LoginDetailInfoPO getResumeBaseInfo() {

        LoginUserInfoPO userInfo = LoginUserContext.getLoginUserInfoPO();

        return userResumeMapper.getResumeBaseInfo(userInfo.getUserId());

    }
}
